package com.leoman.utils;

import com.leoman.user.entity.UserInfo;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SendMsgThread extends Thread {

    public List<UserInfo> userInfoList;

    public String content;

    public List<UserInfo> getUserInfoList() {
        return userInfoList;
    }

    public void setUserInfoList(List<UserInfo> userInfoLists) {
        userInfoList = userInfoLists;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void run() {
        // 发送消息
        try {
            Map<String, Object> map = new HashMap<>();

            for (UserInfo userInfo : userInfoList) {
                if (null == userInfo || StringUtils.isEmpty(userInfo.getRegistrationId())) {
                    continue;
                }

                map.put("alert", content);
                map.put("extras", new HashMap<String, String>());

                JPushUtils.sendMsgByRegistrationId(userInfo.getRegistrationId(), map);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
